import {ref} from 'vue'
import {defineStore} from 'pinia'

export const useUserStore = defineStore('loginUser', () => {
    const token = ref('')
    const setToken = (newToken) => {
        token.value = newToken
    }
    const removeToken = () => {
        token.value = ''
    }

    const user = ref({})
    const setUser = (obj) => {
        user.value = obj
    }
    const removeUser = () => {
        user.value = {}
    }
    const getUser = () => {
        return user.value
    }

    return {
        token,
        setToken,
        removeToken,
        user,
        setUser,
        removeUser,
        getUser
    }

}, {
    persist: {
        storage: sessionStorage
    }
})
